import java.util.Random;

class myThread extends Thread {
    @Override
    public void run() {
        System.out.println("继承Thread，重写run");
    }
}

class myRunableThread implements Runnable {

    @Override
    public void run() {
        System.out.println("实现Runnable，重写run");
    }
}

public class Test1 {

    public static void main(String[] args) throws InterruptedException {
        Thread t3 = new Thread(() -> {
            System.out.println(Thread.currentThread());
        },"c");
        Thread t2 = new Thread(() -> {
            try {
                t3.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread());
        },"b");
        Thread t1 = new Thread(() -> {
            try {
                t2.join();
                t3.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread());
        },"a");
        t1.start();
        t2.start();
        t3.start();
        t1.join();
    }
}

//    static int count = 0;
//    public static void main(String[] args) throws InterruptedException {
//        Test1 test1 = new Test1();
//        Test1 test2 = new Test1();
//        Thread t1 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                synchronized(test1) {
//                    System.out.println(Thread.currentThread()+"获取到锁test1");
//                    synchronized(test2){
//                        System.out.println(Thread.currentThread()+"获取到锁test2");
//                    }
//                }
//            }
//        });
//        Thread t2 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                synchronized(test2) {
//                    System.out.println(Thread.currentThread()+"获取到锁test2");
//                    synchronized(test1){
//                        System.out.println(Thread.currentThread()+"获取到锁test1");
//                    }
//                }
//            }
//        });
//        t1.start();
//        t2.start();
//        t1.join();
//        t2.join();
//    }


//    public static void main(String[] args) throws InterruptedException {
//        Thread[] threads = new Thread[20];
//        for(int i=0; i<20; i++){
//            final int n = i;
//            threads[i] = new Thread(new Runnable() {
//                @Override
//                public void run() {//内部类使用外部的变量，必须是final修饰
//                    System.out.println(n);
//                }
//            });
//        }
//        for(Thread t : threads){
//            t.start();
//        }
//        for(Thread t : threads){//同时执行20个线程，再等待所有线程执行完毕
//            t.join();
//        }
//        System.out.println("OK");
//    }




